class Solution {
    public int maxValue(int[][] grid) {
        int kuan = grid[0].length;
        int gao = grid.length;
        int[][] num = new int[gao][kuan];
        for(int i = 0;i < gao;i++) {
            for(int j = 0;j < kuan;j++) {
                if(i == 0 && j == 0) {
                    num[i][j] = grid[i][j];
                }else if(i == 0) {
                    num[i][j] = grid[i][j] + num[i][j-1];
                }else if(j == 0) {
                    num[i][j] = grid[i][j] + num[i-1][j];
                } else {
                    num[i][j] = grid[i][j] + Math.max(num[i-1][j],num[i][j-1]);
                }
            }
        }
        return num[gao-1][kuan-1];
    }
}